using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Administration.Claims;

namespace Riolinx.SocialConnekt.Community.Receivers
{
    /// <summary>
    /// This class handles events raised during feature activation, deactivation, installation, uninstallation, and upgrade.
    /// </summary>
    /// <remarks>
    /// The GUID attached to this class may be used during packaging and should not be modified.
    /// </remarks>


    public class ClaimProviderFeatureReceiver : SPClaimProviderFeatureReceiver
    {
        // Uncomment the method below to handle the event raised after a feature has been activated.

        private void ExecBaseFeatureActivated(Microsoft.SharePoint.SPFeatureReceiverProperties properties)
        {
            //Wrapper function for base FeatureActivated. Used because base
            //keywork can lead to unverifiable code inside lambda expression.
            //try
            //{
            //    SPSecurityTokenServiceManager manager = SPSecurityTokenServiceManager.Local;

            //    SPTrustedLoginProviderCollection colProviders = manager.TrustedLoginProviders;
            //    SPTrustedLoginProvider pSocialConnekt = null;
            //    foreach (SPTrustedLoginProvider p in colProviders)
            //    {
            //        if (p.Name == Constants.SOCIALCONNEKT_PROVIDER_NAME)
            //        {
            //            pSocialConnekt = p;
            //            break;
            //        }
            //    }
            //    if (pSocialConnekt != null)
            //    {
            //        pSocialConnekt.ClaimProviderName = ClaimProvider.ProviderInternalName;
            //        pSocialConnekt.Update();
            //    }
            //}
            //catch (Exception)
            //{               
            //}



            base.FeatureActivated(properties);
        }

        public override string ClaimProviderAssembly
        {
            get
            {
                return typeof(ClaimProvider).Assembly.FullName;
            }
        }

        public override string ClaimProviderDescription
        {
            get
            {
                return "Augments the user's claims with all incoming claims from social networks such as Windows Live, Facebook, LinkedIn, etc...";
            }
        }

        public override string ClaimProviderDisplayName
        {
            get
            {
                return ClaimProvider.ProviderDisplayName;
            }
        }

        public override string ClaimProviderType
        {
            get
            {
                return typeof(ClaimProvider).FullName;
            }
        }

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            ExecBaseFeatureActivated(properties);
        }

       


        // Uncomment the method below to handle the event raised before a feature is deactivated.

        //public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        //{
        //}


        // Uncomment the method below to handle the event raised after a feature has been installed.

        //public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        //{
        //}


        // Uncomment the method below to handle the event raised before a feature is uninstalled.

        //public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        //{
        //}

        // Uncomment the method below to handle the event raised when a feature is upgrading.

        //public override void FeatureUpgrading(SPFeatureReceiverProperties properties, string upgradeActionName, System.Collections.Generic.IDictionary<string, string> parameters)
        //{
        //}
    }
}
